/********************************************************************************
 * Project Name		[JavaSE_Fundamentals]
 * File Name     	[Inheritance.java]
 * Creation Date 	[2015-01-01]
 * 
 * Copyright© ge.y.yang@gmail.com All Rights Reserved
 * 
 * Work hard, play harder, think big and keep fit
 ********************************************************************************/
package objectOriented;

/**
 * 继承
 * 
 * @author 不落的太阳(Sean Yang aka ShortPeace)
 * @version 1.0
 * @since jdk 1.8
 * 
 */
public class Inheritance {

	public static void main(String[] args) {
		Manager manager = new Manager("Cloud Yang", 30000, 2015, 8, 5);
		manager.setBonus(20000);

		Employee[] staff = new Employee[3];
		staff[0] = manager;
		// staff[0].setBonus(20000);根据多态性:父类引用不能调用子类中新增加的方法
		staff[1] = new Employee("Sean Yang", 20000, 2015, 8, 5);
		staff[2] = new Employee("Ge Yang", 20000, 2015, 8, 5);

		/*
		 * 如果子类不重写toString()方法, 父类的getSalary方法将会被调用
		 */
		for (Employee employee : staff) {
			System.out.println(employee);
		}
	}
}

/**
 * 
 * @author 不落的太阳(Sean Yang aka ShortPeace)
 * @version 1.0
 * @since jdk 1.8
 *
 */
class Manager extends Employee {

	private double bonus;

	/**
	 * 构造方法
	 */
	public Manager() {
		super();
	}

	public Manager(String name, double salary, int year, int month, int day) {
		super(name, salary, year, month, day);
		bonus = 0;
	}

	public double getBonus() {
		return bonus;
	}

	public void setBonus(double bonus) {
		this.bonus = bonus;
	}

	@Override
	public double getSalary() {
		// double baseSalary = getSalary()是递归调用
		double baseSalary = super.getSalary();
		double salary = baseSalary + bonus;
		return salary;
	}

	@Override
	public String toString() {
		return "Id " + this.getId() + "\tname " + this.getName() + "\tsalary " + this.getSalary() + "\thiredate "
				+ this.getHireDate();
	}
}